package com.smt.ejb3.tutoria.extendedpersistencecontext;

import javax.ejb.Remote;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

@Stateful
@Remote
public class StudentManagerBean implements StudentManager {

	@PersistenceContext(unitName = "ejb3db", 
			type=PersistenceContextType.EXTENDED)
	private EntityManager em;
	
	private Student student;
	
	@Override
	public void saveStudent(Student student) {
		em.persist(student);
	}

	@Override
	public Student findStudent(int id) {
		student = em.find(Student.class, id);
		return student;
	}

	@Override
	public void updateName(String name) {
		student.setName(name);
	}

	@Override
	public void updateAge(int age) {
		student.setAge(age);
	}

	@Override
	public void updateAddress(String address) {
		student.setAddress(address);
	}

}
